package com.shr.code_interview;

public class Solution_21 {
    public static void reOrderArray(int [] array) {
//        int front = 0;
//        int end = array.length - 1;
//        while(front < end){
//	        while (array[end] % 2 == 0) end-- ;
//	        while (array[front] % 2 == 1) front++;
//	        if(front < end){
//		        int t = array[end] ;
//		        array[end] = array[front];
//		        array[front] = t;
//	        }
//        }
    	int[] evenArray = new int[array.length];
    	int[] ouArray = new int[array.length];
    	int indexE = 0;
    	int indexO = 0;
    	for(int i = 0;i<array.length;i++){
    		if(array[i] % 2 == 1)
    			evenArray[indexE++] = array[i] ;
    		else ouArray[indexO++] = array[i] ;
    	}
    	System.arraycopy(evenArray, 0, array, 0, indexE);
    	System.arraycopy(ouArray, 0, array, indexE, indexO);
    	
        for(int i = 0;i<array.length;i++)
        	System.out.print(array[i]);
    }	
    
    public static void main(String[] args) {
		reOrderArray(new int[]{2,3,4,5,6,7,8});
	}
}
